home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / h_eq_ct.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  80 lines

  1. ; $Id: h_eq_ct.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro h_eq_ct, image    ;Histogram equalize color tables from image
  8. ;+
  9. ; NAME:
  10. ;    H_EQ_CT
  11. ;
  12. ; PURPOSE:
  13. ;    Histogram-equalize the color tables for an image or a region
  14. ;    of the display.
  15. ;
  16. ; CATEGORY:
  17. ;    Image processing.
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    H_EQ_CT, Image    ;To histogram equalize from an image.
  21. ;    H_EQ_CT        ;To histogram equalize from a region
  22. ;
  23. ; INPUTS:
  24. ;    Image:    Image whose histogram is to be used in determining
  25. ;        the new color tables.  If this value is omitted, the user 
  26. ;        is prompted to mark the diagonal corners of a region of the 
  27. ;        display.
  28. ;
  29. ;        Image MUST be a byte image, scaled the same way as
  30. ;        the image loaded to the display.
  31. ;
  32. ; OUTPUTS:
  33. ;    No explicit outputs.  The result is applied to the current color
  34. ;    tables.
  35. ;
  36. ; COMMON BLOCKS:
  37. ;    COLORS:    The IDL color table common block.
  38. ;
  39. ; SIDE EFFECTS:
  40. ;    The current color table is modified.
  41. ;
  42. ; RESTRICTIONS:
  43. ;    If a parameter is supplied, it is assumed to be an image that
  44. ;    was just displayed.
  45. ;
  46. ; PROCEDURE:
  47. ;    Either the image parameter or the region of the display marked by
  48. ;    the user is used to obtain a pixel-distribution histogram.  The
  49. ;    cumulative integral is taken and scaled.  This function is applied
  50. ;    to the current color tables.
  51. ;
  52. ; MODIFICATION HISTORY:
  53. ;    DMS, March, 1988, written.
  54. ;    DMS, May, 1990, added BOX_CURSOR.
  55. ;    AB, 21 September 1992,renamed from HIST_EQUAL_CT to H_EQ_CT to
  56. ;        avoid DOS filename limitations. HIST_EQUAL_CT is still
  57. ;        available as a wrapper to this routine under operating
  58. ;        systems that can handle longer file names.
  59. ;-
  60.  
  61. common colors,r,g,b,cur_red,cur_green,cur_blue
  62.  
  63. on_error,2                      ;Return to caller if an error occurs
  64. nc = !d.table_size    ;# of colors in device
  65. if nc eq 0 then message, 'Device has static color tables, Can''t adjust'
  66. if n_elements(image) gt 0 then h = histogram(image) $
  67.     else begin
  68.     box_cursor, x0, y0, xs, ys, /message
  69.     h = histogram(tvrd(x0, y0, xs, ys))
  70.     endelse
  71. for i=1,n_elements(h)-1 do h[i] = h[i]+h[i-1]
  72. h = long(bytscl(h, top = nc-1))
  73. if n_elements(r) le 0 then begin    ;color tables defined?
  74.     r=indgen(nc) & g=r & b=r & endif
  75. cur_red = r[h] & cur_green = g[h] & cur_blue = b[h]
  76. tvlct,cur_red, cur_green, cur_blue
  77. return
  78. end
  79.  
  80.